//
//  DMGoodsDetailAppraiseVC.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/16.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMGoodsDetailAppraiseVC.h"
#import "DMGoodsDetailAppraiseCell.h"

@interface DMGoodsDetailAppraiseVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation DMGoodsDetailAppraiseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startInit];
}

-(void)startInit {
    self.navigationItem.title = @"全部评价";
    _dataArray = [NSMutableArray new];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableHeaderView = [self headerView];
    // 如果让autoLayout自动计算cell的高度:
    // 预计的高度:
    _tableView.estimatedRowHeight = 300;
    // 设置行高为自动计算:
    _tableView.rowHeight = UITableViewAutomaticDimension;
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DMGoodsDetailAppraiseCell" bundle:nil] forCellReuseIdentifier:@"DMGoodsDetailAppraiseCell"];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return _dataArray.count;
    return 10;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    return 200;
//}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DMGoodsDetailAppraiseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMGoodsDetailAppraiseCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"DMGoodsDetailAppraiseCell" owner:self options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //TODO:-测试数据
    NSMutableArray *arr = [NSMutableArray new];
    for (int i = 0; i < indexPath.row; i++) {
        [arr addObject:@"机器人机器人机器人"];
    }
    cell.contentLb.text = [arr componentsJoinedByString:@","];
    cell.images = arr;
    return cell;
}

//头部评价类型
-(UIView *)headerView {
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 110)];
    view.backgroundColor = DMWhiteColor;
    
    NSArray *arr = @[@"全部(346)",@"有图(34)",@"好评(346)",@"中评(0)",@"差评(0)"];
    CGFloat width = (ScreenWidth-55)/4;
    CGFloat height = 25;
    for (int i = 0; i < arr.count; i++) {
        int hang = i/4;
        int lie = i%4;
        CGFloat x = 20+lie*(width+5);
        CGFloat y = 20+hang*(height+14);
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(x, y, width, height)];
        [button setTitle:arr[i] forState:UIControlStateNormal];
        if (i == 0) {
            [button setTitleColor:DMWhiteColor forState:UIControlStateNormal];
            button.backgroundColor = DMColor(64, 156, 247);
        } else {
            [button setTitleColor:DMFontColor forState:UIControlStateNormal];
            button.backgroundColor = DMColor(221, 221, 221);
        }
        button.titleLabel.font = DMFontSize(14);
        button.titleLabel.adjustsFontSizeToFitWidth = YES;
        button.layer.cornerRadius = 13;
        [view addSubview:button];
        
    }
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 102, ScreenWidth, 8)];
    line.backgroundColor = DMDefaultColor;
    [view addSubview:line];
    
    return view;
}


@end
